$(function() {
    var url={
        list:'{:url("admin/Finance/FundsManagement_list")}',//列表
        check:'{:url("admin/Finance/check_FundsManagement")}',//通过预充值

    }
    var page = 1;
    var tddata = [{
        key: 'company_recharge_id',
        type: 1,
        url: ''
    }, {
        key: 'date',
        type: 1,
        url: '',
    }, {
        key: 'company_name',
        type: 1,
        url: ''
    }, {
        key: 'null',
        type: 1,
        url: ''
    }, {
        key: 'type2',
        type: 1,
        url: ''
    }, {
        key: 'number',
        type: 1,
        url: ''
    }, {
        key: 'state2',
        type: 1,
        url: ''
    }, {
        key: 'ps',
        type: 1,
        url: ''
    }];
    var addoperation = `<td>
						<div class="tpl-table-black-operation operate">
							
							<a href="javascript:;" class='exit'>
								<i class="am-icon-pencil"></i> 编辑
							</a>
							<a href="javascript:;" class="tpl-table-black-operation-del scrap_close">
								<i class="am-icon-pencil"></i> 取消
							</a>
						</div>
					</td>`
    var data={};
    data.page=page;
    data.pagenum=10;
    var where_json={};

    data.where_json=JSON.stringify(where_json)
    ajaxlist(data)
    function ajaxlist(data) {
        Load()
        $.ajax({
            type: "post",
            url: url.list,
            data: data,
            success: function (res) {
                console.log(res)
                Load(1)

                if (res.code == 1) {
                    for(var stateidx=0;stateidx<res.data.length;stateidx++){

                        if (res.data[stateidx].type == 1) {
                            res.data[stateidx].type2 = '微信充值'
                        } else if (res.data[stateidx].type == 2) {
                            res.data[stateidx].type2 = '预充值'
                        }

                        if (res.data[stateidx].state == 1) {
                            res.data[stateidx].state2 = '微信充值已提交'
                        } else if (res.data[stateidx].state == 2) {
                            res.data[stateidx].state2 = '预充值已提交'
                        } else if (res.data[stateidx].state == 3) {
                            res.data[stateidx].state2 = '已完成'
                        }
                    }
                    $('tbody').html(tbodymainf2(res.data, 1, tddata, addoperation, 'company_recharge_id'))
                    $('.pagination').html(pagechang1(res.count, 10, page))
                    $('tbody tr').each(function(){
                        var operate='';
                        for(var idx=0;idx<res.data.length;idx++){
                            if(res.data[idx].company_recharge_id==$(this).data('id')){
                                if(res.data[idx].state==1 && res.data[idx].type==2 ){
                                    operate=`
										<a href="check_FundsManagement?company_recharge_id=`+res.data[idx].company_recharge_id+`" ><i class="am-icon-pencil "></i> 同意</a>
										`
                                }
                            }
                        }
                        $(this).find('.operate').append(operate)
                    })


                    $('.laquo').on('click', function () {
                        page -= 1;

                        data.page = page
                        ajaxbuycar(data)
                    })
                    $('.pageli').on('click', function () {
                        page = $(this).html()
                        data.page = page
                        ajaxbuycar(data)
                    })
                    //下一页
                    $('.raquo').on('click', function () {
                        page += 1;
                        data.page = page
                        ajaxbuycar(data)
                    });
                    $('.buy_check').on('click', function () {
                        propcheck($(this))
                    })
                    $('.register').on('click', function () {
                        window.location.href = '{:url("add")}?audit=1'
                    })

                    $('.detail').on('click', function () {
                        auditdetail($(this))
                    })
                    $('.scrap_close').on('click', function () {
                        scrapclose($(this))
                    })
                } else {
                    Err('请求失败')
                }
            }
        });
    }
})